package com.jump.user.controller.v1;

import com.jump.user.dto.User;
import com.jump.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * Created by fangxiao on 15/9/1.
 */

@RestController
@RequestMapping("/user/v1")
public class UserController {

    @Autowired
    UserService service;


    /**
     *
     * login
     */
    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public Map login(@RequestBody Map prams) {
        String info = (String)prams.get("info");
        String password = (String)prams.get("password");
        Map map = service.login(info, password);
        return  map;
    }


    /**
     * register
     * @return
     */
    @RequestMapping(value="/register", method = RequestMethod.POST)
    public Map register(@RequestBody Map params) {

        String username = (String)params.get("username");
        String password = (String)params.get("password");
        String mobile = (String)params.get("mobile");
        String email = (String)params.get("email");

        Map map = service.register(username,password,mobile,email);
        return map;
    }





    @RequestMapping(value = "/existusername/{username}", method=RequestMethod.GET)
    public Map existUserName(@PathVariable String username) {
        Map map  = service.exitUserByUserName(username);

        return map;
    }


    @RequestMapping(value = "/existmobile/{mobile}", method=RequestMethod.GET)
    public Map existMobile(@PathVariable String mobile) {
        Map map  = service.exitUserByMobile(mobile);

        return map;
    }

    @RequestMapping(value = "/existemail/{email}", method=RequestMethod.GET)
    public Map existEmail(@PathVariable String email) {
        Map map  = service.exitUserByEmail(email);
        return map;
    }



    @RequestMapping(value = "/certification", method = RequestMethod.POST)
    public Map certification(@RequestBody Map params) {
        Map map = null;
        String userName = (String)params.get("userName");
        String chineseName = (String)params.get("chineseName");
        String idCard = (String)params.get("idCard");
        map = service.Certification(userName, chineseName, idCard);
        return map;
    }

    @RequestMapping(value = "/finishotherinfo", method = RequestMethod.POST)
    public Map finishOtherInfo(@RequestBody User user){
        Map map = null;
        map = service.finishOtherInfo(user);
        return map;
    }

    @RequestMapping(value = "/resetpassword", method = RequestMethod.POST)
    public Map resetPassword(@RequestParam String userName,
                             @RequestParam String oldPassword,
                             @RequestParam String newPassword) {
        Map map = null;
        map = service.resetPassword(userName, oldPassword, newPassword);
        return map;
    }



}
